package com.hencoder.hencoderpracticedraw1.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.View;

public class Practice11PieChartView extends View {

    public Practice11PieChartView(Context context) {
        super(context);
    }

    public Practice11PieChartView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Practice11PieChartView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint p = new Paint();//这个是画矩形的画笔，方便大家理解这个圆弧
        p.setStyle(Paint.Style.STROKE);
        p.setColor(Color.YELLOW);

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);

        paint.setColor(Color.parseColor("#2196F3"));
        RectF rect = new RectF(300, 100, 800, 600);
        canvas.drawArc(rect, 80, 100, true, paint);
//        canvas.drawRect(rect, p);//画矩形

        paint.setColor(Color.parseColor("#FFC107"));
        canvas.drawArc(rect, 300, 60, true, paint);

        paint.setColor(Color.parseColor("#9C27B0"));
        canvas.drawArc(rect, 2, 7, true, paint);

        paint.setColor(Color.parseColor("#9E9E9E"));
        canvas.drawArc(rect, 11, 7, true, paint);

        paint.setColor(Color.parseColor("#009688"));
        canvas.drawArc(rect, 20, 58, true, paint);

        RectF rect2 = new RectF(280, 80, 780, 580);
        paint.setColor(Color.parseColor("#F44336"));
        canvas.drawArc(rect2, 180, 120, true, paint);
        p.setColor(Color.RED);

//        canvas.drawRect(rect2, p);//画矩形

        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(2);

        float x = (float) ((1 - Math.sqrt(2) / 2) * 250 + 280);
        float y = (float) ((1 - Math.sqrt(2) / 2) * 250 + 80);

        canvas.drawLine(x, y, x - 30, y - 30, paint);
        canvas.drawLine(x - 30, y - 30, x - 130, y - 30, paint);

        paint.setColor(Color.WHITE);
        paint.setTextSize(32);
        canvas.drawText("Lolilap", x - 220, y - 30, paint);


        float x1 = (float) ((1 - Math.sqrt(2) / 2) * 250 + 280);
        float y1 = (float) (600 - (1 - Math.sqrt(2) / 2) * 250);
        canvas.drawLine(x1, y1, x1 - 30, y1 + 30, paint);
        canvas.drawLine(x1 - 30, y1 + 30, x1 - 130, y1 + 30, paint);

        paint.setTextSize(32);
        canvas.drawText("Kitkat", x1 - 220, y1 + 30, paint);
//        canvas.drawColor(Color.RED);
//        canvas.drawRect(x, y - 80, x - 80, y - 30, paint);

//        综合练习
//        练习内容：使用各种 Canvas.drawXXX() 方法画饼图
    }
}
